package com.xuyuan.spring.async;

import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author xuyuan
 * @desc SpringBoot提供的异步工具
 */
@Component
public class AsyncService {

    /**
     * 如果不配置异步线程池默认使用SimpleAsyncTaskExecutor。也可以实现AsyncConfigurer自定义线程池。也可以通过@Async注解指定使用的线程池的名称
     *
     * @see SimpleAsyncTaskExecutor
     */
    @Async
    public void asyncMethod() {
        Thread thread = Thread.currentThread();
        System.out.println("thread:" + thread.getName());
    }
}
